import { defineStore} from "pinia";
import {computed, ref} from "vue";
import axios from "axios";
import {ResJS, TitleJS} from "../types/data";


export const useCounterStore = defineStore('counter',() =>{
    // 1.定义变量
    const count = ref(0)

    // 2.定义方法，修改变量
    const increment = () => {
        count.value ++
    }

    // computed 计算属性，有缓存
    const com_value = computed(()=>
        // 里面不要{} 包括
        count.value * 2
    )


    let data_a = ref<TitleJS[]>([])
    // 异步请求数据
    const get_data = async ()=>{
        const res = await axios.request<ResJS>({
            url:'http://geek.itheima.net/v1_0/channels'
        })
        data_a.value = res.data.data.channels
    }



    // 3.返回数据  => 以对象形式返回
    return { count, increment, com_value, get_data,data_a }

})